use axum::{
    extract::State,
    response::Json,
};
use serde_json::{json, Value};
use std::sync::Arc;
use crate::AppState;

pub async fn health_check(State(state): State<Arc<AppState>>) -> Json<Value> {
    // 检查Fluvio集群健康状态
    let fluvio_healthy = state.fluvio.health_check().await.unwrap_or(false);

    let overall_status = if fluvio_healthy { "healthy" } else { "degraded" };

    Json(json!({
        "status": overall_status,
        "service": "fluviox-api-gateway",
        "version": "0.1.0",
        "timestamp": chrono::Utc::now(),
        "components": {
            "fluvio": {
                "status": if fluvio_healthy { "healthy" } else { "unhealthy" },
                "endpoint": state.config.fluvio.cluster_endpoint
            },
            "database": {
                "status": "healthy" // TODO: 实际检查数据库状态
            }
        }
    }))
}
